package com.sxt;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;

import org.junit.Test;

public class test2 {
	public static void main(String[] args) throws Exception{
		
	
	String r = "http://i1.hdslb.com/bfs/face/dea862adbff072552df1f3158125c7d9abc12392.jpg";
	URL url =new URL(r);
	InputStream in = url.openStream();
	FileOutputStream fo = new FileOutputStream(new File("D:/root2/"+r.split("/")[r.split("/").length-1]));//文件输出流
	
	byte [] buf = new byte[1024];  
	int lenth = 0;
	while((lenth = in.read(buf, 0, buf.length))!=-1){
	    	fo.write(buf, 0, lenth);
	    }
	 fo.close();
	 in.close();
	 System.out.println("下载完成");
	}
	/*@Test
	public void test(){
		String str = "a/b/c/b/dad.jpg";
		System.out.println(str);
		String [] s =str.split("/");
		
		System.out.println(s[s.length-1]);
	}*/
}

